package com.daka.controller;

import com.daka.entity.ActivitySign;
import com.daka.entity.SocialActivity;
import com.daka.enumerate.StatusCode;
import com.daka.service.ActivitySignRecordService;
import com.daka.service.SocialActivityService;
import com.daka.vo.request.ActivityVo;
import com.daka.vo.response.BaseResponseVo;
import com.daka.vo.response.DataResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yangx
 * CreateTime: 2016/9/18 10:13
 */

@Controller
@RequestMapping("/activitySign")
@Slf4j
public class ActivitySignController {

    @Autowired
    private SocialActivityService socialActivityService;
    @Autowired
    private ActivitySignRecordService activitySignRecordService;

    @ResponseBody
    @RequestMapping(value = "/sign",method = RequestMethod.POST,produces = "application/json; charset=UTF-8")
    public DataResponseVo<Object> sign(@RequestBody ActivityVo vo){
        if(vo.getMemberID()==null || vo.getActivityCode()==null || vo.getLat()==null || vo.getLng()==null){
            return new DataResponseVo(StatusCode.COMMON_PARAM_ERROR.getCode(),StatusCode.COMMON_PARAM_ERROR.getMessage());
        }
        ActivitySign activitySign = null;
        activitySign = activitySignRecordService.sign(vo.getMemberID(), vo.getActivityCode(), vo.getLng(), vo.getLat());
        Map<String ,Object> map = new HashMap<String, Object>();
        map.put("volunteerTime",activitySign.getVolunteerTime());
        return new DataResponseVo<Object>(StatusCode.OK.getCode(), StatusCode.OK.getMessage(),map);
    }


    @ResponseBody
    @RequestMapping(value = "/signSocial",method = RequestMethod.POST,produces = "application/json; charset=UTF-8")
    public BaseResponseVo signSocial (@RequestBody SocialActivity po){
        if(po.getStudentCode()==null || po.getName()==null ||po.getMobile()==null ||po.getCollege()==null ||po.getDepartment()==null ||
                po.getClasses()==null ||po.getActivityName()==null ||po.getLat()==null || po.getLng()==null){
            return new BaseResponseVo(StatusCode.COMMON_PARAM_ERROR.getCode(),StatusCode.COMMON_PARAM_ERROR.getMessage());
        }
        socialActivityService.insert(po);
        return new BaseResponseVo(StatusCode.OK.getCode(), StatusCode.OK.getMessage());
    }
}









